<?php


namespace App\Services;
use App\Model\GoldCardLog;
use App\Model\ShopGoodModel;
use App\Model\ShopOrderFstModel;
use App\Model\SkuModel;
use App\Model\StoreGoodModel;
use App\Model\StoreModel as Store;
use App\Model\StoreModel;
use App\Model\UserModel;
use App\Model\UserWalletLogModel as UserWalletLog;
use App\Model\UserWalletModel;
use App\Model\ConfigModel;
use App\Model\YjLog;
use App\Model\Config;
use Carbon\Carbon;
use function GuzzleHttp\Promise\all;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;


class Msfl
{

    //转货款判断是累计够一万元(一年内),足够的话升银卡,本身是通过交388服务费升级银卡的,退还388服务费到货款
    public function ten_thoundsand($uid)
    {
        $vip_one = ConfigModel::getValue('vip_one'); //388
        $vip_two = ConfigModel::getValue('vip_two'); //10000
        $level_one_ratio = ConfigModel::getValue('level_one_ratio'); //创客奖上级
        $level_two_ratio = ConfigModel::getValue('level_two_ratio'); //创客奖上上级
        //判断是否已经是会员
        $user = UserModel::where('id',$uid)->first();
        if($user->level > 0) {
            Log::info('判断是会员');
            $stores = Store::where('uid', $uid)->first();
            $start_time = $stores->start;
            $end_time = $stores->end;
            $hk_sum = UserWalletLog::where('uid', $uid)
                ->where('status', '3')
                ->where('sign', '+')
                ->where('created_at', '>=', $start_time)
                ->where('created_at', '<=', $end_time)
                ->sum('num');
            //累计充值10000,并且第一次是388开通的银卡
            if ($hk_sum >= $vip_two && $stores->type == 1) {
                DB::beginTransaction();
                Log::info('退还服务费开始');
                try {
                    if (!empty($is_has = UserWalletLog::where('uid', $uid)
                        ->where('status', 13)
                        ->where('created_at','>',date("Y-m-d H:i:s",strtotime("-365 days")))
                        ->orderby('id','desc')
                        ->first())) {
                        Log::info(date("Y-m-d H:i:s",strtotime("-365 days")));
                        Log::info('已经退还过服务费'.$is_has);//继续加货款,不退还服务费
//                        return;
                    }else{
                        UserWalletModel::handleAccount($uid, $vip_one, '+',
                            '累计货款' . $vip_two . '退还' . $vip_one, 2, 13, '', $user['id']);
                    }
//                    Log::info(date("Y-m-d H:i:s",strtotime("-365 days")));

                    DB::commit();
//                    return ['code'=>1,'msg'=>retStrInfo(93)];
                } catch (Exception $e) {
                    DB::rollBack();
                    Log::info('退还' . $vip_one . '服务费异常' . $e);
                    throw $e;
//                    return ['code'=>0,'msg'=>retStrInfo(94)];
                }
            }
            Log::info('累计货款数:'.$hk_sum.',vip货款:'.$vip_two.',仓库开通方式,'.$stores->type);
        }else{
        	if($user['is_auth'] != 1){
        		return ;
			}
                //不是银卡会员
            $stores = Store::where('uid', $uid)->first();

//            $start_time = $stores->start;
//            $end_time = $stores->end;
            if(!empty($stores)){
                $end_time = $stores->end;
                $hk_sum = UserWalletLog::where('uid', $uid)
                    ->where('status', '3')
                    ->where('sign', '+')
                    ->where('created_at', '>=', $end_time)
                    ->sum('num');
            }else{
                $hk_sum = UserWalletLog::where('uid', $uid)
                    ->where('status', '3')
                    ->where('sign', '+')
                    ->sum('num');
            }
            if($hk_sum < $vip_two){
                Log::info('累计充值货款不足'.$vip_two.'不能升级银卡');
                return;
            }
//            \Log::info('累计货款:'.$hk_sum.',vip货款:'.$vip_two);
//            return;

                try {

                    //开启云仓库
                    if(Store::where('uid',request()->uid)->first()){
                        $store = Store::where('uid',request()->uid)->update([
                            'start' => date('Y-m-d H:i:s'),
                            'end' => date('Y-m-d H:i:s',strtotime('+365 days')),
                            'is_end' => 1,
                        ]);
                    }else{
                        $store = Store::create([
                            'uid' => request()->uid,
                            'start' => date('Y-m-d H:i:s'),
                            'end' => date('Y-m-d H:i:s',strtotime('+365 days')),
                            'state' => 1,
                            'type' => 1,
                        ]);
                    }
                    //升级成为银级
                    UserModel::where('id', request()->uid)->update(['level' => 1,'is_vip'=>1]);
                    //一代
                    $puser = UserModel::where('id', $user['pid'])->first();
                    if ($puser) {
                        if($puser['level'] > 0){
                            //一代二代赠送货款
                            UserWalletModel::handleAccount($puser['id'], $level_one_ratio, '+', '创客奖', 2, 12, 'user', $user['id']);
                        }
                        
                    }

                    //二代
                    $tuser = UserModel::where('id', $puser['pid'])->first();

                    if ($tuser) {
                        if($tuser['level'] > 0){
                            //一代二代赠送货款
                            UserWalletModel::handleAccount($tuser['id'], $level_two_ratio, '+', '创客奖', 2, 12, 'user', $user['id']);
                        }
                        
                    }
                    DB::commit();
                } catch (Exception $e) {
                    DB::rollBack();
                    Log::info('累计充值一万升级银卡失败' . $e);
                    throw $e;
                }
            }
        }

    //计算个人业绩
    public function person_yj($uid,$price){
		DB::beginTransaction();
		try{
			$user = UserModel::where('id',$uid)->first();

			if($user['is_auth'] != 1){
				return ['code'=>0,'msg'=>retStrInfo(95)];
			}

//			if($user->level > 0){
				//销售奖
				$this->sell_reword($uid,$price);
//			}
			//教育奖
//			$this->education_reword($uid,$price);

			Log::info('增加个人业绩开始');

			if($user->level > 0){

				$before = UserModel::where('id',$uid)->value('person_yj');

				UserModel::where('id',$uid)->increment('person_yj',$price);

				$after = UserModel::where('id',$uid)->value('person_yj');
				/*
				 * $uid 用户id(给谁加)
				 * $price 业绩数
				 * sign 加或减
				 * msg  描述
				 * before 未加业绩之前的值
				 * after 加业绩之后的值
				 * type 1个人业绩 2团队业绩
				 * status 1报单
				 */
				YjLog::add_log($uid,$price,'+','购买商品',$before,$after,1,1,'');
			}
			Log::info('增加个人业绩结束');

			//计算团队业绩
			$this->team_yj($uid,$price);

			//判断是自己否升金卡
			$this->up_vip2($uid);

			DB::commit();
		}catch(Excpetion $e){
			DB::rollBack();
		}


    }
    //计算团队业绩
    public function team_yj($uid,$price,$type=1){
        Log::info('增加团队业绩开始'.$uid);
        //找上级
        $user = UserModel::where('id',$uid)->first();

        if($user->pid == 0){

            Log::info('上级id为0找上级结束');
            return ;
        }
        //上级id不为0,给上级增加团队业绩
        $before = UserModel::where('id',$user->pid)->value('team_yj');

        UserModel::where('id',$user->pid)->increment('team_yj',$price);
        $after = UserModel::where('id',$user->pid)->value('team_yj');

        /*
         * $uid 用户id(给谁加)
         * $price 业绩数
         * sign 加或减
         * msg  描述
         * before 未加业绩之前的值
         * after 加业绩之后的值
         * type 1个人业绩 2团队业绩
         * status 1报单
         * uid 报单人id
         */
        if($type == 1){
            YjLog::add_log($user->pid,$price,'+','下级购买商品',$before,$after,2,1,$uid);
        }else{
            YjLog::add_log($user->pid,$price,'+','下级转货款',$before,$after,2,1,$uid);
        }
        Log::info('增加团队业绩用户id'.$user->pid);
        Log::info('增加团队业绩结束');

    }
    //计算个人奖励:销售奖(个人报单时调用,业绩(零售价)的6% (现金)(用户自己购买))
    public function sell_reword($uid,$price)
    {
        Log::info('计算销售奖开始');
        $user = UserModel::where('id',$uid)->first();
        
        if($user->level == 1){
            $person_yj_rate = ConfigModel::getValue('person_yj_rate');
        }elseif($user->level == 2){
            $all_yj = bcadd($user->person_yj,$user->team_yj,5);
            $duan = bcsub($all_yj,2000,5);
            Log::info($duan);
//            return;
            if($duan <= 0){
                $person_yj_rate = ConfigModel::getValue('person_yj_jin_rate');
            }else{
                $num = floor(bcdiv($duan,3000,5));//有几个3000,一个3000多1.5%
                if($num>=8){
                    $num = 8;
                }
                $person_yj_rate = ConfigModel::getValue('person_yj_jin_rate')+($num*0.015);
            }
        }elseif($user->level == 0){
			$person_yj_rate = 0;
		}

        $xsj = bcmul($price,$person_yj_rate,5);
        /*
         * uid 用户id
         * sxj 奖金数额
         * msg 描述
         * type 1现金 2货款
         * status 消费类型(type=1 1充值 2提现 3转货款 4成为VIP 5销售奖 6领导奖 7教育奖 8云仓库收益 9后台充值  type=2 3转货款 10入库 11下单 12创客奖 13累计充值够10000返利388)
         * dy_table 对应表
         * dy_id  对应id
         */
		if($xsj > 0){
			UserWalletModel::handleAccount($uid,$xsj,'+','销售奖',1,5);
		}

        Log::info('计算销售奖结束');
        Log::info('计算领导奖开始');

        $this->sales_incentive($uid,$price,$person_yj_rate);
       
        Log::info('计算领导奖结束');
    }

    //判断是否升金卡(条件:先是银卡,个人业绩达到两千)
    public function up_vip2($uid)
    {
        $user = UserModel::where('id',$uid)->first();
        if($user->level == 1 && $user->person_yj >= 2000){
            Log::info('升级金卡开始');
            UserModel::where('id',$user->id)->update(['level'=>2]);
            Log::info('升级金卡结束');
            //生成一条记录
            $edu_rate = ConfigModel::where('name','edu_rate')->value('value');
            $jiesuan_day = ConfigModel::where('name','jiesuan_day')->value('value');
            $this->edu_reward($uid,$edu_rate,$jiesuan_day);
        }
    }

    //(停用)领导奖(销售奖极差),找直推,上级销售奖要大于自己的销售奖,上级销售奖减去自己的销售奖获得比例就是领导奖比例
    /*
     * $uid 用户id
     * $price 报单价格
     * $person_yj_rate 个人销售奖比例
     */
//    public function sales_incentive($user,$price,$person_yj_rate)
//    {
//        $pid = $user->pid;
//        if($pid == 0){
//            Log::info('自身为顶级账号,结束查找');
//            return;
//        }
//        //获取上级所得销售奖比例
//        $puser = UserModel::where('id',$pid)->first();
//        if($puser){
//            if($puser->level > 0){
//
//                if($puser->level == 1){
//                    $puser_yj_rate = ConfigModel::getValue('person_yj_rate');
//                }elseif($puser->level == 2){
//                    $all_yj = bcadd($puser->person_yj,$puser->team_yj,5);
//                    $duan = bcsub($all_yj,2000,5);
//        //            Log::info($duan);
//        //            return;
//                    if($duan <= 0){
//                        $puser_yj_rate = ConfigModel::getValue('person_yj_jin_rate');
//                    }else{
//                        $num = floor(bcdiv($duan,3000,5));//有几个3000,一个3000多1.5%
//                        if($num>=8){
//                            $num = 8;
//                        }
//                        $puser_yj_rate = ConfigModel::getValue('person_yj_jin_rate')+($num*0.015);
//                    }
//                }
//
//                //如果上级销售奖比例大于下级则有领导奖否则没有
//                if($puser_yj_rate > $person_yj_rate){
//        //		dd($puser_yj_rate);
//                    $rate = $puser_yj_rate - $person_yj_rate;
//                    $reword = bcmul($price,$rate,5);
//                    /*
//                     * uid 用户id
//                     * sxj 奖金数额
//                     * msg 描述
//                     * type 1现金 2货款
//                     * status 消费类型(type=1 1充值 2提现 3转货款 4成为VIP 5销售奖 6领导奖 7教育奖 8云仓库收益 9后台充值  type=2 3转货款 10入库 11下单 12创客奖 13累计充值够10000返利388)
//                     * dy_table 对应表
//                     * dy_id  报单用户id
//                     */
//                    UserWalletModel::handleAccount($user->pid,$reword,'+','领导奖',1,6,'',$user->id);
//
//                }
//            }
//        }
//    }

    //教育奖 例:d报单 c和b的个人业绩要达到一万 a的个人业绩达到两千  a得教育奖3%
    public function education_reword($uid,$price){
        Log::info('计算教育奖开始');
        $pid = UserModel::where('id',$uid)->value('pid');

        if($pid <= 0){
        	return ;
		}
        $cuser = UserModel::where('id',$pid)->first(); //c
		if($cuser){
			$buser = UserModel::where('id',$cuser->pid)->first(); //b
		}
		if($buser){
			$auser = UserModel::where('id',$buser->pid)->first(); //a
		}
        if(!empty($cuser) && !empty($buser) && !empty($auser)){
            $bc_yj = bcadd($buser->person_yj,$cuser->person_yj,5);
            $a_yj = $auser->person_yj;
            if($bc_yj >= 10000 && $a_yj >= 2000){
                $jyj = bcmul($price,0.03,5); //教育奖
                /*
                 * uid 用户id
                 * sxj 奖金数额
                 * msg 描述
                 * type 1现金 2货款
                 * status 消费类型(type=1 1充值 2提现 3转货款 4成为VIP 5销售奖 6领导奖 7教育奖 8云仓库收益 9后台充值  type=2 3转货款 10入库 11下单 12创客奖 13累计充值够10000返利388)
                 * dy_table 对应表
                 * dy_id  报单用户id
                 */
                UserWalletModel::handleAccount($auser->id,$jyj,'+','教育奖',1,7,'',$uid);
            }
        }
        Log::info('计算教育奖结束');
    }

    //循环加销量减库存
    /*
     * shop_id 商品id
     * sku_id sku_id
     * num   数量
     * fid   子订单id
     */
    public function min_store($shop_id,$sku_id,$num,$fid)
    {
    	$profit_ratio = ConfigModel::getValue('profit');
        //减只减这个人商品的数量,加销量,如果这个数量过多一个用户的云仓库不够减就继续调用
        if(!empty($sku_id)){ //多规格
            $all_store = StoreGoodModel::with(['store'=>function($query){
                $query->where('state',1)->where('is_end'); //查出有货且云仓库没有冻结和关闭的
            }])
                ->where('sku_id',$sku_id)
                ->where('num','>',0)
                ->orderby('id','asc')
                ->get();
            if(count($all_store) < 1){
                return; //没有该商品的云仓库就停止
            }
            foreach ($all_store as $k => $v){
                //判断这个仓库的货物是否足够
                if($v->num >= $num){
                    StoreGoodModel::where('id',$v->id)->decrement('num',$num);//足够 //仓库减库存
                    StoreGoodModel::where('id',$v->id)->increment('sale_num',$num);//仓库加销量
//                    ShopGoodModel::where('id',$shop_id)->increment('sale_num',$num);//加销量shop
                    //生成记录
                    $shop = ShopGoodModel::where('id',$shop_id)->first();
                    $sku = SkuModel::where('id',$sku_id)->first();
                    ShopOrderFstModel::add($fid,$shop_id,$v->id,$num,$sku->cost_price,$sku->sell_price,
                        bcmul($sku->sell_price,$num,5),$shop->picpath.$shop->picname,$shop->name,$sku_id,$sku->property);
                    break;
                }else{
                    StoreGoodModel::where('id',$v->id)->decrement('num',$v->num);//不够 //仓库减库存
                    StoreGoodModel::where('id',$v->id)->increment('sale_num',$v->num);// 仓库加销量
//                    ShopGoodModel::where('id',$shop_id)->increment('sale_num',$v->num);//加销量shop
                    //生成记录
                    $shop = ShopGoodModel::where('id',$shop_id)->first();
                    $sku = SkuModel::where('id',$sku_id)->first();
                    ShopOrderFstModel::add($fid,$shop_id,$v->id,$v->num,$sku->cost_price,$sku->sell_price,
                        bcmul($sku->sell_price,$v->num,5),$shop->picpath.$shop->picname,$shop->name,$sku_id,$sku->property);
                    $num -= $v->num;
                }

            }
			//查询商品详情
			$store_good_info = StoreGoodModel::where('id',$v['id'])->first();
			//商品名
			$gname = ShopGoodModel::where('id',$store_good_info['gid'])->value('name');
			//计算利益
			$profit = bcmul($sku['sell_price'],$profit_ratio,2);
			$profit = bcadd($store_good_info['gsell_price'],$profit,2);
			$profit = $profit*$num;
			//给仓库所有者增加收益
			$user_store_uid = StoreModel::where('id',$v['sid'])->value('uid');
			UserWalletModel::handleAccount($user_store_uid,$profit,'+','商品['.$gname.']下单,获得收益','1','15','NULL','0');
        }else{ //单规格
            $all_store = StoreGoodModel::with(['store'=>function($query){
                $query->where('state',1)->where('is_end'); //查出有货且云仓库没有冻结和关闭的
            }])
                ->where('gid',$shop_id)
                ->where('num','>',0)
                ->orderby('id','asc')
                ->get();
            if(count($all_store) < 1){
                return; //没有该商品的云仓库就停止
            }
            foreach ($all_store as $k => $v){
                //判断这个仓库的货物是否足够
                if($v->num >= $num){
                    StoreGoodModel::where('id',$v->id)->decrement('num',$num);//足够
                    StoreGoodModel::where('id',$v->id)->increment('sale_num',$num);//加销量sku
//                    ShopGoodModel::where('id',$shop_id)->increment('sale_num',$num);//加销量shop
                    //生成记录
                    $shop = ShopGoodModel::where('id',$shop_id)->first();
                    ShopOrderFstModel::add($fid,$shop_id,$v->id,$num,$shop->cost_price,$shop->sell_price,
                        bcmul($shop->sell_price,$num,5),$shop->picpath.$shop->picname,$shop->name,0,0);

					//查询商品详情
					$store_good_info = StoreGoodModel::where('id',$v['id'])->first();
					//商品名
					$gname = ShopGoodModel::where('id',$store_good_info['gid'])->value('name');
					//计算利益
					$profit = bcmul($shop['sell_price'],$profit_ratio,2);
					$profit = bcadd($store_good_info['gsell_price'],$profit,2);
					$profit = $profit*$num;
					//给仓库所有者增加收益
					$user_store_uid = StoreModel::where('id',$v['sid'])->value('uid');
					UserWalletModel::handleAccount($user_store_uid,$profit,'+','商品['.$gname.'下单],获得收益','1','15','NULL','0');

                    break;
                }else{
                    StoreGoodModel::where('id',$v->id)->decrement('num',$v->num);//不够
                    StoreGoodModel::where('id',$v->id)->increment('sale_num',$v->num);//加销量
//                    ShopGoodModel::where('id',$shop_id)->increment('sale_num',$v->num);//加销量shop
                    //生成记录
                    $shop = ShopGoodModel::where('id',$shop_id)->first();
                    ShopOrderFstModel::add($fid,$shop_id,$v->id,$v->num,$shop->cost_price,$shop->sell_price,
                        bcmul($shop->sell_price,$v->num,5),$shop->picpath.$shop->picname,$shop->name,0,0);
                    $num -= $v->num;

					//查询商品详情
					$store_good_info = StoreGoodModel::where('id',$v['id'])->first();
					//商品名
					$gname = ShopGoodModel::where('id',$store_good_info['gid'])->value('name');
					//计算利益
					$profit = bcmul($shop['sell_price'],$profit_ratio,2);
					$profit = bcadd($store_good_info['gsell_price'],$profit,2);
					$profit = $profit*$v->num;
					//给仓库所有者增加收益
					$user_store_uid = StoreModel::where('id',$v['sid'])->value('uid');
					UserWalletModel::handleAccount($user_store_uid,$profit,'+','商品['.$gname.']下单,获得收益'.$profit,'1','15','NULL','0');
                }
            }
        }


    }

    //增加业绩
    /***
     * uid    用户ID
     * num    转货款数量
     */
    public function performance($uid,$num){
        DB::beginTransaction();
        try{
            $user = UserModel::where('id',$uid)->first();

            if($user['is_auth'] != 1){
                return ['code'=>0,'msg'=>retStrInfo(95)];
            }

            Log::info('增加个人业绩开始');

            if($user->level > 0){

                $before = UserModel::where('id',$uid)->value('person_yj');

                UserModel::where('id',$uid)->increment('person_yj',$num);

                $after = UserModel::where('id',$uid)->value('person_yj');
                /*
                * $uid 用户id(给谁加)
                * $price 业绩数
                * sign 加或减
                * msg  描述
                * before 未加业绩之前的值
                * after 加业绩之后的值
                * type 1个人业绩 2团队业绩
                * status 1报单
                */
                YjLog::add_log($uid,$num,'+','转货款',$before,$after,1,1,'');
            }
            Log::info('增加个人业绩结束');
            //计算团队业绩
            $this->team_yj($uid,$num,2);
            //判断是自己否升金卡
            $this->up_vip2($uid);
            DB::commit();
        }catch(Excpetion $e){
            DB::rollBack();
        }
    }

    public function edu_reward($uid,$edu_rate,$jiesuan_day)
    {
        $jiesuan_day+=30;
        //先判断是否有记录,有就不生成了
        if(!empty(GoldCardLog::where('uid',$uid)->where('state',2)->first())){
            return;
        }
        $gold_card_log = new GoldCardLog();
        $gold_card_log->uid = $uid;
        $now = date('Y-m-d h:i:s',time());
        $gold_card_log->start_time = $now;
        $gold_card_log->end_time = date("Y-m-d H:i:s",strtotime("30 day"));
        $gold_card_log->jiesuan_time = date("Y-m-d",strtotime($jiesuan_day."day"));
        $gold_card_log->state = 2;
        $gold_card_log->edu_rate = $edu_rate;
        $gold_card_log->save();
    }

    //计算上两代业绩,为教育奖服务
    public function father_yeji($uid,$yeji)
    {
        //找直推上级,给当前金卡记录表加业绩
        $pid = UserModel::where('id',$uid)->value('pid');
        if($pid != 0){
            GoldCardLog::where('uid',$pid)->where('state',2)->increment('all_yeji',$yeji);
            $ppid = UserModel::where('id',$pid)->value('pid');
            if($ppid != 0){
                GoldCardLog::where('uid',$ppid)->where('state',2)->increment('all_yeji',$yeji);
            }
        }
    }

    //计算领导奖
    public function sales_incentive($uid,$price,$lj_rate = 0)
    {
        $pid = UserModel::where('id',$uid)->value('pid');
        if($pid == 0){
            Log::info('自身为顶级账号,结束查找');
            return;
        }
        if($lj_rate >= 0.195){
            Log::info('比例达到最大,停止发奖');
            return;
        }
        //获取上级所得销售奖比例
        $puser = UserModel::where('id',$pid)->first();
            if($puser->level > 0){
                if($puser->level == 1){
                    $puser_yj_rate = ConfigModel::getValue('person_yj_rate');
                }elseif($puser->level == 2){
                    $all_yj = bcadd($puser->person_yj,$puser->team_yj,5);
                    $duan = bcsub($all_yj,2000,5);
                    if($duan <= 0){
                        $puser_yj_rate = ConfigModel::getValue('person_yj_jin_rate');
                    }else{
                        $num = floor(bcdiv($duan,3000,5));//有几个3000,一个3000多1.5%
                        if($num>=8){
                            $num = 8;
                        }
                        $puser_yj_rate = ConfigModel::getValue('person_yj_jin_rate')+($num*0.015);
                    }
                }

                //如果上级销售奖比例大于下级则有领导奖否则没有
                if($puser_yj_rate > $lj_rate){
                    $rate = $puser_yj_rate - $lj_rate;
                    $reword = bcmul($price,$rate,5);
                    /*
                     * uid 用户id
                     * sxj 奖金数额
                     * msg 描述
                     * type 1现金 2货款
                     * status 消费类型(type=1 1充值 2提现 3转货款 4成为VIP 5销售奖 6领导奖 7教育奖 8云仓库收益 9后台充值  type=2 3转货款 10入库 11下单 12创客奖 13累计充值够10000返利388)
                     * dy_table 对应表
                     * dy_id  报单用户id
                     */
                    UserWalletModel::handleAccount($pid,$reword,'+','领导奖',1,6,'',$uid);
                    Log::info('领导奖分发',['uid'=>$pid,'num'=>$reword,'lj_rate'=>$lj_rate,'rate'=>$rate]);
                    return $this->sales_incentive($pid,$price,$puser_yj_rate);
                }else{
                    return $this->sales_incentive($pid,$price,$lj_rate);
                }
            }
            return $this->sales_incentive($pid,$price,$lj_rate);

    }
}